package com.shenmazong.servertalkadmin.controller;

import com.shenmazong.servertalkadmin.service.impl.TbSellerServiceImpl;
import com.shenmazong.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@Api(tags = "接口-销售管理微服务")
public class SellerController {
    @Autowired
    private TbSellerServiceImpl sellerService;

    /**
     * TODO 添加销售
     *
     * @Description:
     * @Author: 尹绪瑞
     * @Date: 2020/9/9 10:34
     * @return: java.lang.ResponseResult
     **/
    @PostMapping("/addSellerUser")
    @ApiOperation(value = "添加销售", notes = "管理员添加销售")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", required = true),
            @ApiImplicitParam(name = "nickName", value = "销售员名字", dataType = "String", required = true),
            @ApiImplicitParam(name = "mobile", value = "手机号", dataType = "String", required = true),
            @ApiImplicitParam(name = "sex", value = "性别", dataType = "int", required = true, example = "0"),
            @ApiImplicitParam(name = "age", value = "年龄", dataType = "int", required = true, example = "0"),
            @ApiImplicitParam(name = "saleFee", value = "收费标准", dataType = "Long", required = true, example = "0"),
            @ApiImplicitParam(name = "address", value = "地址", dataType = "String", required = true)
    })
    public ResponseResult addSellerUser(
            @RequestParam("userName") String userName,
            @RequestParam("mobile") String mobile,
            @RequestParam("nickName") String nickName,
            @RequestParam("sex") Integer sex,
            @RequestParam("age") Integer age,
            @RequestParam("saleFee") Long saleFee,
            @RequestParam("address") String address) {
        return sellerService.addSellerUser(mobile, userName, nickName, sex, age, saleFee, address);

    }

    /**
     * TODO 删除销售
     *
     * @Description:
     * @Author: 尹绪瑞
     * @Date: 2020/9/9 10:34
     * @return: java.lang.ResponseResult
     **/
    @PostMapping("/delSellerUser")
    @ApiOperation(value = "删除销售", notes = "管理员删除销售")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "id", value = "销售编号", dataType = "int", required = true, example = "0")
    })
    public ResponseResult delSellerUser(@RequestParam("id") Integer id) {
        return sellerService.delSellerUser(id);

    }

    /**
     * TODO 修改销售密码
     *
     * @Description:
     * @Author: 尹绪瑞
     * @Date: 2020/9/9 10:37
     * @return: java.lang.ResponseResult
     **/


    @ApiOperation(value = "修改销售密码", notes = "销售管理平台修改销售密码")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId ", value = "销售编号", dataType = "int", required = true, example = "0"),
            @ApiImplicitParam(name = "oldPass", value = "旧密码", dataType = "String", required = true),
            @ApiImplicitParam(name = "newPass", value = "新密码", dataType = "String", required = true)
    })
    @PostMapping(value = "/setSellerPass")
    public ResponseResult setSellerPass(@RequestParam("userId") Integer userId,
                                      @RequestParam("oldPass") String oldPass,
                                      @RequestParam("newPass") String newPass) {
        return sellerService.setSellerPass(userId, oldPass, newPass);
    }

    /**
     * TODO 修改销售信息
     *
     * @Description:
     * @Author: 尹绪瑞
     * @Date: 2020/9/9 10:43
     * @return: java.lang.ResponseResult
     **/
    @PostMapping("/setSellerInfo")
    @ApiOperation(value = "修改销售信息", notes = "管理员修改销售信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userId", value = "销售编号", dataType = "int", required = true, example = "0"),
            @ApiImplicitParam(name = "nickName", value = "销售员名字", dataType = "String", required = true),
            @ApiImplicitParam(name = "mobile", value = "手机号", dataType = "String", required = true),
            @ApiImplicitParam(name = "sex", value = "性别", dataType = "int", required = true, example = "0"),
            @ApiImplicitParam(name = "age", value = "年龄", dataType = "int", required = true, example = "0"),
            @ApiImplicitParam(name = "saleFee", value = "收费标准", dataType = "Long", required = true, example = "0"),
            @ApiImplicitParam(name = "address", value = "地址", dataType = "String", required = true)
    })
    public ResponseResult setSellerInfo(@RequestParam("userId") Integer userId,
                                        @RequestParam("nickName") String nickName,
                                        @RequestParam("mobile") String mobile,
                                        @RequestParam("sex") Integer sex,
                                        @RequestParam("age") Integer age,
                                        @RequestParam("saleFee") Long saleFee,
                                        @RequestParam("address") String address) {
        return sellerService.setSellerInfo(userId, nickName, mobile, sex, age, address);

    }

    /**
     * TODO 销售登陆
     *
     * @Description:
     * @Author: 尹绪瑞
     * @Date: 2020/9/9 10:39
     * @return: java.lang.ResponseResult
     **/
    @PostMapping("/doSellerLogin")
    @ApiOperation(value = "销售登陆", notes = "管理平台销售登陆")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "userName", value = "用户名", dataType = "String", required = true),
            @ApiImplicitParam(name = "passWord", value = "密码", dataType = "String", required = true)
    })
    public ResponseResult doSellerLogin(@RequestParam("userName") String userName,
                                        @RequestParam("passWord") String passWord
    ) {
        return sellerService.doSellerLogin(userName, passWord);

    }

    @PostMapping(value = "/getSellerByPage")
    @ApiOperation(value = "销售员列表", notes = "返回所有销售员的信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageCurrent", value = "用户名", dataType = "int", required = true, example = "0"),
            @ApiImplicitParam(name = "pageSize", value = "密码", dataType = "int", required = true, example = "0")
    })
    public ResponseResult getSellerByPage(
            @RequestParam("pageCurrent") Integer pageCurrent,
            @RequestParam("pageSize") Integer pageSize) {
        return sellerService.getSellerList(pageCurrent, pageSize);
    }

    @ApiOperation(value = "获取销售员信息", notes = "获取销售员信息")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name="sellerId", value = "销售员id", dataType = "int", required=true, example = "0")
    })
    @PostMapping(value = "/getSellerInfo")
    public ResponseResult getSellerInfo(@RequestParam("sellerId") Integer sellerId) {
        return sellerService.getSellerInfo(sellerId);
    }
}
